import type * as T from './type'
import http from '@/utils/http'
import type { LabelValueState } from '@/types/global'

export type * from './type'

/**
 * 用户字典
 */
export function listUserDict(query: T.UserPageQuery) {
  return http.post<LabelValueState[]>(`/system/user/dict`, query)
}

/**
 * 用户列表
 * @param query
 */
export function listUser(query: T.UserPageQuery) {
  return http.post<T.UserResp[]>(`/system/user/list`, query)
}

/**
 * 用户分页
 * @param query
 */
export function pageUser(query: T.UserPageQuery) {
  return http.post<PageRes<T.UserResp[]>>(`/system/user/page`, query)
}

/**
 * 用户详情
 * @param id
 */
export function getUser(id: string) {
  return http.get<T.UserDetailResp>(`/system/user/detail/${id}`)
}

/**
 * 新增用户
 * @param data
 */
export function addUser(data: any) {
  return http.post(`/system/user/create`, data)
}

/**
 * 修改用户
 * @param data
 * @param id
 */
export function updateUser(data: any, id: string) {
  return http.put(`/system/user/update/${id}`, data)
}

/**
 * 删除用户
 * @param ids
 */
export function deleteUser(ids: string | Array<string>) {
  return http.del(`/system/user/delete/${ids}`)
}

/**
 * 重置密码
 * @param data
 * @param id
 */
export function resetUserPwd(data: any, id: string) {
  return http.patch(`/system/user/${id}/password/reset`, data)
}

/**
 * 导出用户
 * @param query
 */
export function exportUser(query: T.UserQuery) {
  return http.download(`/system/user/export`, query)
}

/**
 * 下载用户导入模板
 */
export function downloadUserImportTemplate() {
  return http.download(`/system/user/import/template/download`)
}

/**
 * 解析用户导入数据
 * @param data
 */
export function parseImportUser(data: FormData) {
  return http.post(`/system/user/import/parse`, data)
}

/**
 * 导入用户
 * @param data
 */
export function importUser(data: any) {
  return http.post(`/system/user/import`, data)
}
